<?php

use App\Kuafu\Base\Enum\DBEnum;
use App\Kuafu\Category\Model\CategoryModel;
use App\Kuafu\Product\Model\Product;
use App\Kuafu\ProductMenu\Model\ProductMenu;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;

class AddMenuIdToCategory extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('category', function (Blueprint $table) {
            $table->unsignedInteger('menuId')->default(0)->after('id');
            $table->index('menuId', 'idx_menuId');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        ProductMenu::query()->where('menuId', '!=', 0)->forceDelete();

        Schema::table('category', function (Blueprint $table) {
            $table->dropColumn('menuId');
        });
    }
}
